package juice;

import juice.DI$typeOfannotation.HelloGuice;
import junit.Order;
import junit.OrderedRunner;
import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.Test;
import org.junit.runner.RunWith;

import com.google.inject.Guice;
import com.google.inject.Injector;

/**
 * 对Guice类库的测试
 * 
 * @author Beanstao@gmail.com
 * 
 */
@RunWith(OrderedRunner.class)
public class TestBaseGuice extends TestCase
{
	/*
	 * guice 得到的实体不是单例的
	 */
	@Test
	@Order(order = 1)
	public void testSingleton()
	{
		Injector injector = Guice.createInjector();
		HelloGuice guice = injector.getInstance(HelloGuice.class);
		HelloGuice guice2 = injector.getInstance(HelloGuice.class);
		System.out.println("testSingleton() -- " + guice.hashCode() + " >> " + guice2.hashCode());
		Assert.assertNotSame(guice, guice2);
	}

	/*
	 * guice 返回一个正常的实例，并没有做过多的转换和代理。
	 */
	@Test
	@Order(order = 2)
	public void testImpl()
	{
		Injector injector = Guice.createInjector();
		HelloGuice guice = injector.getInstance(HelloGuice.class);
		System.out.println("testImpl() -- " + guice.getClass().getName());
	}

	/**
	 * Guice多实现绑定到同一个接口上：通过自定义注解方式实现了，测试见TestMultiInterface。
	 */
	public void testMoreImpl()
	{
	}
}
